package cn.cm.config;

import com.alibaba.fastjson.JSON;
import org.apache.shiro.web.filter.authc.UserFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author shikundai
 * @date 2021/6/28
 * @time 16:15
 * @description: shiro未认证的重定向
 */
public class LoginFilter extends UserFilter {
    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
        /*
        * 如果用户没有登录就会进入到这个方法
        * */
        OutData outData=new OutData();
        outData.setCode(500);
        outData.setMsg("you are not Login!");

        response.getWriter().print(JSON.toJSONString(outData));
    }
}
